﻿using Desktop.Interfaces;
using System;
using System.Runtime.Serialization;

namespace Desktop.Library
{
    /// <summary>
    /// A piece of a chapter.
    /// </summary>
    [Serializable()]
    public class Section : ContentItem<Section>
    {
        #region Variables

        private string _text;

        #endregion

        #region Constructors

        public Section()
            : base()
        {
            Text = string.Empty;
        }

        public Section(Section section)
            : base(section)
        {
            if (section == null)
            {
                return;
            }
            Text = section.Text;
        }

        public Section(SerializationInfo info, StreamingContext context)
            : base(info, context)
        {
            Text = info.GetString("Text");
        }

        #endregion

        #region Properties

        public string Text
        {
            get
            {
                return _text;
            }
            set
            {
                if (_text != value)
                {
                    PropertyHasChanged("Text");
                }
                _text = value;
            }
        }

        #endregion

        #region Methods

        public override string ToString()
        {
            return Text;
        }

        public override void GetObjectData(SerializationInfo info, StreamingContext context)
        {
            info.AddValue("Text", Text);
            base.GetObjectData(info, context);
        }

        #endregion
    }
}